﻿// 1.3.1.2.5. Formula Bit -> http://bgcoder.com/Contest/Practice/79 

using System;

class FormulaBit
{
    static void Main()
    {
        int[,] area = new int[8, 8];

        for (int row = 0; row < 8; row++)
        {
            int n = int.Parse(Console.ReadLine());
            for (int col = 7; col >= 0; col--)
            {
                area[row, col] = (n >> (7 - col)) & 1;
            }
        }

        int stepCounter = 0;
        int turnCounter = 0;

        int verticalPos = 0;
        int horizontalPos = 7;

        while (true)
        {
            if (area[verticalPos, horizontalPos] == 1)
            {
                Console.WriteLine("No {0}", stepCounter);
                break;
            }
            

            for (int row = verticalPos; row < 8; row++) // DOWN 
            {
                if (area[verticalPos, horizontalPos] == 0)
                {
                    stepCounter++;

                }
                if (area[verticalPos, horizontalPos] == 1 | row == 7)
                {
                    break;
                }

                verticalPos++;
            }

            if (verticalPos == 7 & horizontalPos == 0)
            {
                Console.WriteLine("{0} {1}", stepCounter, turnCounter);
                break;
            }

            if (verticalPos >= 0)
            {
                verticalPos--;
            }
            if (horizontalPos >= 0)
            {
                horizontalPos--;
            }


            if (area[verticalPos, horizontalPos] == 1)
            {
                Console.WriteLine("No {0}", stepCounter);
                break;
            }


            turnCounter++;


            for (int col = horizontalPos; col >= 0; col--)  // LEFT 
            {
                if (area[verticalPos, horizontalPos] == 0)
                {
                    stepCounter++;
                }
                if (area[verticalPos, horizontalPos] == 1 | col == 0)
                {
                    break;
                }

                horizontalPos--;
            }

            if (verticalPos == 7 & horizontalPos == 0)
            {
                Console.WriteLine("{0} {1}", stepCounter, turnCounter);
                break;
            }

            if (horizontalPos <= 7)
            {
                horizontalPos++;
            }
            if (verticalPos >= 0)
            {
                verticalPos--;
            }


            if (area[verticalPos, horizontalPos] == 1)
            {
                Console.WriteLine("No {0}", stepCounter);
                break;
            }


            turnCounter++;


            for (int row = verticalPos; row >= 0; row--)    // UP 
            {
                if (area[verticalPos, horizontalPos] == 0)
                {
                    stepCounter++;
                }
                if (area[verticalPos, horizontalPos] == 1 | row == 0)
                {
                    break;
                }
                verticalPos--;
            }
            //verticalPos++; 

            if (verticalPos == 7 & horizontalPos == 0)
            {
                Console.WriteLine("{0} {1}", stepCounter, turnCounter);
                break;
            }

            if (horizontalPos >= 0)
            {
                horizontalPos--;
            }


            if (area[verticalPos, horizontalPos] == 1)
            {
                Console.WriteLine("No {0}", stepCounter);
                break;
            }


            turnCounter++;


            for (int col = horizontalPos; col >= 0; col--)  // LEFT 
            {
                if (area[verticalPos, horizontalPos] == 0)
                {
                    stepCounter++;
                }
                if (area[verticalPos, horizontalPos] == 1 | col == 0)
                {
                    break;
                }
                horizontalPos--;
            }
            //horizontalPos++; 
            if (verticalPos == 7 & horizontalPos == 0)
            {
                Console.WriteLine("{0} {1}", stepCounter, turnCounter);
                break;
            }

            if (verticalPos <= 7)
            {
                verticalPos++;
            }




            turnCounter++;

        }




        // for (int i = 0; i < 8; i++) 
        // { 
        //     for (int j = 0; j < 8; j++) 
        //     { 
        //         Console.Write(area[i, j]); 
        //     } 
        //     Console.WriteLine(); 
        // } 
    }
}